window.Index = {
    _menus: [
        {
            "menuId": "1",
            "icon": "icon-sys",
            "menuName": "系统管理",
            "menus": [
                {
                    "menuId": "10",
                    "icon": "icon-sys",
                    "menuName": "基础数据",
                    "menus": [
                        {
                            "menuId": "100",
                            "menuName": "平台管理",
                            "icon": "icon-nav",
                            "url": window.BASEPATH + "app/platform.html"
                        },
                        {
                            "menuId": "101",
                            "menuName": "店铺管理",
                            "icon": "icon-nav",
                            "url": window.BASEPATH + "app/shop.html"
                        },
                        {
                            "menuId": "102",
                            "menuName": "接口管理",
                            "icon": "icon-nav",
                            "url": window.BASEPATH + "app/platform_shop.html"
                        },
                        {
                            "menuId": "103",
                            "menuName": "菜品管理",
                            "icon": "icon-nav",
                            "url": window.BASEPATH + "app/dish.html"
                        },
                        {
                            "menuId": "104",
                            "menuName": "订单管理",
                            "icon": "icon-nav",
                            "url": window.BASEPATH + "app/order.html"
                        }
                    ]
                },
                {
                    "menuId": "2",
                    "icon": "icon-sys",
                    "menuName": "测试一",
                    "menus": [
                        {
                            "menuId": "20",
                            "menuName": "测试一11",
                            "icon": "icon-nav",
                            "url": "#"
                        },
                        {
                            "menuId": "200",
                            "menuName": "测试一22",
                            "icon": "icon-nav",
                            "url": "#"
                        }
                    ]
                }
            ]
        },
        {
            "menuId": "20",
            "icon": "icon-sys",
            "menuName": "积分管理",
            "menus": [
                {
                    "menuId": "20",
                    "icon": "icon-sys",
                    "menuName": "积分管理",
                    "menus": [
                        {
                            "menuId": "211",
                            "menuName": "积分用途",
                            "icon": "icon-nav",
                            "url": "#"
                        },
                        {
                            "menuId": "213",
                            "menuName": "积分调整",
                            "icon": "icon-nav",
                            "url": "#"
                        }
                    ]
                }
            ]
        }
    ],

    clearNav: function () {
        var titles = [];
        var pp = $('.easyui-accordion').accordion('panels');
        $.each(pp, function (i, n) {
            if (n) {
                var title = n.panel('options').title;
                titles.push(title);
                //$('.easyui-accordion').accordion('remove', title);
            }
        });

//        pp = $('.easyui-accordion').accordion('getSelected');
//        if (pp) {
//            var title = pp.panel('options').title;
//            titles.push(title);
//            //$('.easyui-accordion').accordion('remove', title);
//        }

        $.each(titles, function (ix, item) {
            $('.easyui-accordion').accordion('remove', item);
        });
    },

    /**
     * 顶部一级菜单
     */
    addTopBar: function () {
        var menuList = "";
        $.each(Index._menus, function (ix, item) {
            if (ix == 0) {
                menuList = '<li><a class="active" name="' + item.menuId + '" href="javascript:;" title="' + item.menuName + '">' + item.menuName + '</a></li> ';
            } else {
                menuList += '<li><a name="' + item.menuId + '" href="javascript:;" title="' + item.menuName + '">' + item.menuName + '</a></li> ';
            }
        });

        $("#css3menu").html(menuList);
    },

    /**
     * 左边二级菜单
     * @param data
     */
    addNav: function (menuId) {
        $.each(Index._menus, function (i, oneItem) {
                if (oneItem.menuId == menuId) {
                    $.each(oneItem.menus, function (j, twoItem) {
                        var menuList = "";
                        menuList += '<ul>';
                        $.each(twoItem.menus, function (k, threeItem) {
                            menuList += '<li><div><a ref="' + threeItem.menuId + '" href="#" rel="'
                                + threeItem.url + '" ><span class="icon ' + threeItem.icon
                                + '" >&nbsp;</span><span class="nav">' + threeItem.menuName
                                + '</span></a></div></li> ';
                        });
                        menuList += '</ul>';

                        $('.easyui-accordion').accordion('add', {
                            title: twoItem.menuName,
                            content: menuList,
                            iconCls: 'icon ' + twoItem.icon
                        });
                    });
                }
            }
        );

        var pp = $('.easyui-accordion').accordion('panels');
        if (pp != null && pp.length > 0) {
            var t = pp[0].panel('options').title;
            $('.easyui-accordion').accordion('select', t);
        }
    },

    InitLeftMenu: function () {
        Index.hoverMenuItem();
        $('.easyui-accordion li a').bind('click', function () {
            var tabTitle = $(this).children('.nav').text();
            var url = $(this).attr("rel");
            var menuId = $(this).attr("ref");
            var icon = Index.getIcon(menuId, icon);

            Index.addTab(tabTitle, url, icon);
            $('.easyui-accordion li div').removeClass("selected");
            $(this).parent().addClass("selected");
        });
    },

    /**
     * 菜单项鼠标Hover
     */
    hoverMenuItem: function () {
        $(".easyui-accordion").find('a').hover(function () {
            $(this).parent().addClass("hover");
        }, function () {
            $(this).parent().removeClass("hover");
        });
    },

    /**
     * 三级菜单图标
     * @param menuId
     * @returns {string}
     */
    getIcon: function (menuId) {
        var icon = 'icon ';
        $.each(Index._menus, function (i, oneItem) {
            $.each(oneItem.menus, function (j, twoItem) {
                $.each(twoItem.menus, function (k, threeItem) {
                    if (threeItem.menuId == menuId) {
                        icon += threeItem.icon;
                        return false;
                    }
                });
            });
        });
        return icon;
    },

    /**
     * 选项卡添加
     * @param subtitle
     * @param url
     * @param icon
     */
    addTab: function (subtitle, url, icon) {
        if (!$('.easyui-tabs').tabs('exists', subtitle)) {
            $('.easyui-tabs').tabs('add', {
                title: subtitle,
                content: Index.createFrame(url),
                closable: true,
                icon: icon
            });
        } else {
            $('.easyui-tabs').tabs('select', subtitle);
            $('#mm-tabupdate').click();
        }
        Index.tabClose();
    },

    /**
     * 床架iframe
     * @param url
     * @returns {string}
     */
    createFrame: function (url) {
        var s = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
        return s;
    },

    /**
     * 关闭选项卡
     */
    tabClose: function () {
        /* 双击关闭TAB选项卡 */
        $(".tabs-inner").dblclick(function () {
            var subtitle = $(this).children(".tabs-closable").text();
            $('.easyui-tabs').tabs('close', subtitle);
        });
        /* 为选项卡绑定右键 */
        $(".tabs-inner").bind('contextmenu', function (e) {
            $('#mm').menu('show', {
                left: e.pageX,
                top: e.pageY
            });

            var subtitle = $(this).children(".tabs-closable").text();
            $('#mm').data("currtab", subtitle);
            $('.easyui-tabs').tabs('select', subtitle);
            return false;
        });
    },
    /**
     * 绑定右键菜单事件
     */
    tabCloseEven: function () {
        // 刷新
        $('#mm-tabupdate').click(function () {
            var currTab = $('.easyui-tabs').tabs('getSelected');
            var url = $(currTab.panel('options').content).attr('src');
            $('.easyui-tabs').tabs('update', {
                tab: currTab,
                options: {
                    content: Index.createFrame(url)
                }
            });
        });
        // 关闭当前
        $('#mm-tabclose').click(function () {
            var currtab_title = $('#mm').data("currtab");
            $('.easyui-tabs').tabs('close', currtab_title);
        });
        // 全部关闭
        $('#mm-tabcloseall').click(function () {
            $('.tabs-inner span').each(function (i, n) {
                var t = $(n).text();
                $('.easyui-tabs').tabs('close', t);
            });
        });
        // 关闭除当前之外的TAB
        $('#mm-tabcloseother').click(function () {
            $('#mm-tabcloseright').click();
            $('#mm-tabcloseleft').click();
        });
        // 关闭当前右侧的TAB
        $('#mm-tabcloseright').click(function () {
            var nextall = $('.tabs-selected').nextAll();
            if (nextall.length == 0) {
                // msgShow('系统提示','后边没有啦~~','error');
                alert('后边没有啦~~');
                return false;
            }
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                $('.easyui-tabs').tabs('close', t);
            });
            return false;
        });
        // 关闭当前左侧的TAB
        $('#mm-tabcloseleft').click(function () {
            var prevall = $('.tabs-selected').prevAll();
            if (prevall.length == 0) {
                alert('到头了，前边没有啦~~');
                return false;
            }
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                $('.easyui-tabs').tabs('close', t);
            });
            return false;
        });

        // 退出
        $("#mm-exit").click(function () {
            $('#mm').menu('hide');
        });
    },

    /**
     * 弹出信息窗口
     * @param title 标题
     * @param msgString 提示信息
     * @param msgType 信息类型 [error,info,question,warning]
     */
    msgShow: function (title, msgString, msgType) {
        $.messager.alert(title, msgString, msgType);
    },

    /**
     * 本地时钟
     */
    clockOn: function () {
        var now = new Date();
        var year = now.getFullYear(); // getFullYear getYear
        var month = now.getMonth();
        var date = now.getDate();
        var day = now.getDay();
        var hour = now.getHours();
        var minu = now.getMinutes();
        var sec = now.getSeconds();
        var week;
        month = month + 1;
        if (month < 10)
            month = "0" + month;
        if (date < 10)
            date = "0" + date;
        if (hour < 10)
            hour = "0" + hour;
        if (minu < 10)
            minu = "0" + minu;
        if (sec < 10)
            sec = "0" + sec;
        var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
        week = arr_week[day];
        var time = "";
        time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + minu
            + ":" + sec + " " + week;

        $("#bgclock").html(time);

        var timer = setTimeout("clockOn()", 200);
    }
}
;